(function () {
    var body=$("body");
    var win=tag.div("poa;w800;h450;l0;r0;m0a;mt-200;bg#888;t50%;c#fff");
    var status=tag.div("w100%;h50;bg#777");
    //本地收藏
    var urls=[];
    var lsgUrls=lsg("urls");
    if(lsgUrls!==null){
        urls=lsgUrls.split(",");
    }else {
        urls=[
            "www.baidu.com",
            "www.taobao.com",
            "www.sina.com.cn",
            "www.iqiyi.com",

            "www.jd.com",
            "www.qq.com",
            "jx.tmall.com",
            "www.bilibili.com"
        ]
    }
    lss("urls",urls);
    localStorage.removeItem("urls");
    win.append(status);
    //init status
    (function () {
        var prefer=tag.div("dib;w100;h50;bg#666;tac;fl;lh50").html("收藏");
        var sug=tag.div("dib;w100;h50;bg#666;tac;fl;lh50").html("推荐");
        var close=tag.div("dib;fr;w100;h50;lh50;tac;tr300;bg#666").html("关闭")
            .hover(
                function () {
                    $(this).mst("bg#f00")},
                function () {
                    $(this).mst("bg#666")})
            .click(function () {
                showMode(0);
            });
        status.append(
            prefer,
            tag.div("h50;w1;bg#333;fl"),
            sug,
            tag.div("fl;h50;w400;cup").click(function () {
                showMode(2)
            }),
            close)
    })();
    //init box
    var box=tag.div("w100%;h400");
    (function () {
        win.append(box);
        var site=new Array(8);
        function setBigColor(iUrl,tag) {


        }
        for(var i=0;i<8;i++) {
            site[i]=tag.div("dib;fl;w200;h200;por;ofh");
            //模糊背景
            var img=$("<img src='http://"+urls[i]+"/favicon.ico'>")
                .mst("w120%;h120%;poa;t-10%;l-10%").css("filter","blur(40px)");
            //图标加网址
            var img2=tag.div("bgiurl('http://"+urls[i]+"/favicon.ico');" +
                "w100%;h30;poa;b-30;tr300;bgs20px 20px;bgp6px center;bgrn;ofh;pl30;lh30")
                .html(urls[i]);
            //网站名字特写
            var name=urls[i].split(".")[1];//截取的网站名
            var big=tag.span().mst("fz50").html(name.substr(0,1).toUpperCase()).css("text-shadow","2px 2px 2px #000");
            var nameBox=tag.div("w100%;h100%;lh200;fz26;poa;t0;l0;tac").append(
                big,
                tag.span().html(name.substr(1)).css("text-shadow","2px 2px 2px #000")
            );
            setBigColor("http://"+urls[i]+"/favicon.ico",big);
            //内容盒子
            var t=tag.div("w100%;h100%;t0;l0;poa;bgrgba(0,0,0,0.2);cup;tr300").append(img2,nameBox).click(function () {
                window.location.href="http://"+urls[$(this).attr("data-i")];
            }).attr("data-i",i).hover
            (function () {
                $(this).mst("bgnone");
                $(this.firstChild).mst("b0");
            },function () {
                $(this).mst("bgrgba(0,0,0,0.2)");
                $(this.firstChild).mst("b-30");
            });
            site[i].append(img,t);
            box.append(site[i]);
        }
    })();
    body.append(win);

    //整合search
    win.mst("tr300;ofh");
    function hideGuide() {
        win.mst("h0")
    }
    function showGuide() {
        win.mst("h450")
    }
    $(window).bind("keydown",function () {
        if(Win.list===undefined){
            showMode(2)
        }
    });
    //双击背景 弹出搜索窗口
    var temp=1;
    window.searchClose.click(function () {
        showMode(0)
    });

    $("#c_bg").dblclick(function () {
        temp++;
        showMode(temp);
        temp===2&&(temp=-1);
    });
    function showMode(t) {
        if(t!==undefined){
            temp=t;
        }
        if(temp===0){
            hideWin();
            hideGuide();
        }else if(temp===1){
            showGuide();
            hideWin();
        }else if(temp===2){
            showWin();
            hideGuide();
        }
    }
    showMode(0);
})();